home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / shell / vector11.lha / src / adddesc.c next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  2.4 KB  |  119 lines

  1. /* AddDesc for AXsh v1.0 by Guru Gnosis Sahib */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <libraries/dos.h>
  6. #include <dos/var.h>
  7. #include <dos/dostags.h>
  8.  
  9. main(int argc, char *argv[])
  10. {
  11.     FILE *input, *output;
  12.     BPTR lock;
  13.     char ulpath[80], descpath[80], filename[80], fullfile[80],
  14.         temp[80], temp2[80];
  15.     int success, nofile, superuser = FALSE;
  16.  
  17.     success = GetVar("accesslevel", temp, 80, GVF_LOCAL_ONLY);
  18.     if(!stricmp(temp, "superuser") || !stricmp(temp, "wizard") ||
  19.         !stricmp(temp, "assistant") || !stricmp(temp, "system"))
  20.         superuser = TRUE;
  21.  
  22. /* Open up config files and set things up */
  23.  
  24.     puts("AddDesc for AXsh v1.0 by Guru Gnosis Sahib");
  25.     if(argc != 2 && superuser == FALSE)
  26.     {
  27.         puts("Usage: AddDesc <filename>\n");
  28.         exit(0);
  29.     }
  30.     strcpy(filename, argv[1]);
  31.     strcpy(ulpath, "Storage:Temp/");
  32.  
  33.     if(!(input = fopen("AXsh:etc/rc.ffe", "r")))
  34.     {
  35.         puts("AddDesc: AXsh:etc/rc.ffe not found");
  36.         exit(0);
  37.     }
  38.     while(!feof(input))
  39.     {
  40.         fgets(temp, 80, input);
  41.         if(temp[0] == '%')
  42.         {
  43.             if(!(strnicmp(temp, "%descpath:", 9)))
  44.             {
  45.                 fscanf(input, "%s", descpath);
  46.                 break;
  47.             }
  48.         }
  49.     }
  50.     fclose(input);
  51.  
  52. /* The main loop */
  53.  
  54.     if(argc != 2)
  55.     {
  56.         puts("\nEnter name of uploaded file: (ENTER to finish)");
  57.         gets(filename);
  58.         if(!strcmp(filename, ""))
  59.         {
  60.             puts("Aborted.");
  61.             exit(0);
  62.         }
  63.     }
  64.     strcpy(fullfile, ulpath);
  65.     strcat(fullfile, filename);
  66.     lock = Lock(fullfile, ACCESS_READ);
  67.     nofile = FALSE;
  68.     if(lock == 0)
  69.     {
  70.         strcpy(fullfile, filename);
  71.         lock = Lock(fullfile, ACCESS_READ);
  72.         if(lock == 0)
  73.         {
  74.             puts("File not found!");
  75.             nofile = TRUE;
  76.         }
  77.     }
  78.     if(lock != 0 || superuser == TRUE)
  79.     {
  80.         UnLock(lock);
  81.         sprintf(temp, "%s%s.dsc", descpath, filename);
  82.         lock = Lock(temp, ACCESS_READ);
  83.         UnLock(lock);
  84.         if(lock != 0)
  85.         {
  86.             puts("Description written already!");
  87.             if(superuser == TRUE)
  88.             {
  89.                 puts("Overwrite description? (y/N)");
  90.                 fgets(temp2, 80, stdin);
  91.                 if(!strnicmp(temp2, "y", 1)) lock = 0;
  92.             }
  93.         }
  94.         if(lock == 0)
  95.         {                
  96.             if(!(output = fopen(temp, "w")))
  97.             {
  98.                 puts("AddDesc: Could not open description file");
  99.                 exit(0);
  100.             }
  101.             puts("Enter a description for the file: (ENTER alone to finish)");
  102.             while(strcmp(temp, ""))
  103.             {
  104.                 gets(temp);
  105.                 fprintf(output, "%s\n", temp);
  106.             }
  107.             fclose(output);
  108.             if(nofile == FALSE)
  109.             {
  110.                 sprintf(temp, "touch >NIL: \"%s\"", fullfile);
  111.                 success = System(temp, TAG_END);
  112.                 sprintf(temp, "protect >NIL: \"%s\" +rwed", fullfile);
  113.                 success = System(temp, TAG_END);
  114.             }
  115.         }
  116.     }
  117.     exit(0);
  118. }
  119.